package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.WhitepaperSubscribeDao;
import com.bestcem.xm.user.dao.mapper.WhitepaperSubscribeMapper;
import com.bestcem.xm.user.entity.mysql.WhitepaperSubscribe;
import com.bestcem.xm.user.entity.pojo.WhitepaperSubscribeDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.WhitepaperSubscribeConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/7/14 23:16
 */
@Repository
public class WhitepaperSubscribeDaoImpl implements WhitepaperSubscribeDao {
    @Resource
    private WhitepaperSubscribeMapper whitepaperSubscribeMapper;
    @Resource
    private WhitepaperSubscribeConvert convert;
    @Override
    public WhitepaperSubscribeDO getOneByPhone(String phone) {
        return convert.mysqls2Do(whitepaperSubscribeMapper.getOneByPhone(phone));
    }

    @Override
    public String insertSelective(WhitepaperSubscribeDO whitepaperSubscribeDO) {
        WhitepaperSubscribe whitepaperSubscribe = convert.do2Mysql(whitepaperSubscribeDO);
        DataBaseUtil.setCreateAndUpdateTime(whitepaperSubscribe);
        whitepaperSubscribe.setId(DataBaseUtil.generateId());
        whitepaperSubscribeMapper.insertSelective(whitepaperSubscribe);
        return whitepaperSubscribe.getId();
    }
}
